<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑页面</title>
    <style type="text/css">
        input[type=text]{
            width: 600px;
        }
        h1{
            text-align: center;
        }
        #wrap{
            width: 800px;
            margin: 60px auto;
        }
        .form-item{
            margin: 50px;
        }
        .form-item label{
            display: inline-block;
            width: 100px;
        }

        /*上传图片样式*/
        #pic-upload-wrap{
            position: fixed;
            right: 20px;
            top: 200px;
            border: 2px dashed gray;
        }
    </style>
</head>
<body>
    <h1>编辑页面</h1>
    <div id="wrap">

        <form action="/blog/index.php?r=site/setedititem&edit_type={%$smarty.get.edit_type%}" method="post">
            <input type="hidden" name="id" value="{%$item.id|default:''%}" />
            <input type="hidden" name="realationid" value="{%$item.realationid|default:'1'%}" />
            <input type="hidden" name="sequence" value="{%$item.sequence|default:'0'%}" />
            <div class="form-item">
                <label>描述：</label><input name="description" type="text" value="{%$item.description|default:''%}" />
            </div>
            <div class="form-item">
                <label>跳转链接：</label><input name="tourl" type="text" value="{%$item.tourl|default:''%}" />
            </div>
            <div class="form-item">
                <label>相关联图片：</label><input id="frontcover-input" name="url" type="text" value="{%$item.url|default:''%}" />
            </div>
            <div class="form-item">
                <label for="ispublish">发布<input {%if $item.ispublish=='1'%}checked{%/if%} id="ispublish" name="ispublish" type="checkbox" value="1" /></label>
            </div>

            <div class="form-item">
                <input type="submit" value="提交" />
            </div>
        </form>
    </div>

    <div id="pic-upload-wrap">
        <form method="post" action="/blog/index.php?r=site/upload" enctype="multipart/form-data">
            <input type="file" name="file" id="file" />
            <input id="frontcover-upload-btn" type="button" value="确认上传" />
        </form>
    </div>


    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

    <script type="text/javascript">
        jQuery( function(){

            var $ = jQuery;

            var $frontcoverBtn = $('#frontcover-upload-btn');
            var $frontcoverInput = $('#frontcover-input');

            var frameIndex = 0;

            $frontcoverBtn.click( function(){

                var form = this.parentNode;
                var frame = document.createElement('iframe');
                var frameID = 'upload-frame-' + frameIndex++;
                frame.id = frameID;
                frame.style.display = 'none';
                document.body.appendChild( frame );
                frame.onload = pictureUpload;
                form.target = frameID;

                form.submit();
            });

            function pictureUpload(){
                var content = this.contentDocument.body.innerHTML;
                console.log( content );
                document.body.removeChild( this );
                $frontcoverInput.val( content );
            }
        });
    </script>
</body>
</html>